<template>
	<view>
		<view style="margin: 20upx;background-color: #fff;padding: 20upx;border-radius: 20upx;">
			<view style="text-align: right;" @click="jump" data-src='/pages/zzjl/zzjl'>
				转账记录
			</view>
			<view style="width: 100%;text-align: center;">
				<view style="font-size: 48upx;font-weight: 600;color: #EC2D16;">
					{{money}}
				</view>
				<view style="font-size: 24upx;">
					可转移积分
				</view>
			</view>
			<view style="font-size: 24upx;height: 80upx;line-height: 80upx;margin-top: 40upx;border-bottom: 1upx solid #dddddd;">
				<text>对方编号</text><input type="text" @blur='Idblur' style="text-align: center; border: none;display: inline-block;width: 298upx;height: 70upx;vertical-align: middle;margin-left: 50upx;" @input="phoneInput"/><text style="margin-left: 50upx;"></text>
			</view>
			<view style="font-size: 24upx;height: 80upx;line-height: 80upx;margin-top: 40upx;border-bottom: 1upx solid #dddddd;">
				<text>转移积分</text><input type="text" style="text-align: center; border: none;display: inline-block;width: 190upx;height: 70upx;vertical-align: middle;margin-left: 120upx;" @input="numInput"/><text style="margin-left: 50upx;"></text>
			</view>
		 </view>
		 <view v-if="otherid" style="text-align: center;">
		 	对方ID:{{otherid}}
		 </view>
		 <view class="btn" style="margin-top: 20upx;width: 80%;margin-left: 10%;">
		 	<button class="logout" @click="open()"  style="font-size: 34upx;height: 80upx;line-height: 80upx;border-radius: 40upx;">确认转移</button>
		 </view>
		 <number-jpan :length="6" @closeChange="closeChange($event)" ref="numberPad"></number-jpan>
	</view>
</template>

<script>
	import numberJpan from "@/components/numberJpan/numberJpan.vue";
	export default {
		data() {
			return {
				res:[],
				num:'',
				money:'',
				openid:'',
				mobile:'',
				phone: '',
				paypass:'',
				otherid:'',
			};
		},
		components: {
			numberJpan
		},
		onShow:function(){
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data
					this.setajax()
				},
				fail: () => {
					uni.navigateTo({
						url: '../../login/login'
					});
				}
			});
		},
		methods:{
			numInput(e){
				this.num = e.target.value
			},
			phoneInput(e){
				this.mobile = e.target.value
			},
			jump(e){
				uni.navigateTo({
					url: e.currentTarget.dataset.src
				});
			},
			open(){
				this.$refs.numberPad.open()//打开数字输入框
				//this.$refs.numberPad.close()//关闭数字输入框
			},
			Idblur(e){
				console.log(e)
				var data1 = {
						'otheropenid': this.mobile,
					}
				uni.request({
					url: 'http://m.wpweipin.com/app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=order.luckdraw.hz_member&app=1',
					method: 'POST',
					data: data1,
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						console.log(res)
						// uni.showToast({
						// 	title: res.data.otherid,
						// 	icon:"none"
						// });
						this.otherid=res.data.otherid
					},
					fail: () => {},
					complete: () => {}
				});
			},
			closeChange(res){
				console.log({res})
				this.paypass = res
				this.submit()
			},
			setajax(){
				var data = {
						'openid': this.openid,
					}
				uni.request({
					url: 'http://m.wpweipin.com/app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=order.luckdraw.member_hz&app=1',
					method: 'POST',
					data: data,
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						console.log(res)
						this.money=res.data.money
					},
					fail: () => {},
					complete: () => {}
				});
			},
			submit(){
				if (this.num==''||this.num==undefined){
					uni.showToast({
							title: '请输入转移数量',
							icon: 'none'
					});
					return
				}
				if (this.mobile==''||this.mobile==undefined){
					uni.showToast({
							title: '请输入对方编号',
							icon: 'none'
					});
					return
				}
				var data = {
						'openid': this.openid,
						'mobile': this.mobile,
						'num': this.num,
						'paypass':this.paypass,
					}
					console.log(data)
				uni.request({
					url: 'http://m.wpweipin.com/app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=order.luckdraw.member_rotation&app=1',
					method: 'POST',
					data: data,
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: (res) => {
						console.log(res)
						uni.showToast({
							title: res.data.message,
							icon:"none"
						});
						if(res.data.error==0){
							setTimeout(()=>{
								uni.switchTab({//跳转到我的页
									url:'../member/member'
								})
							},1000)
						}
					},
					fail: () => {},
					complete: () => {}
				});
			}
		}
	}
</script>

<style>
	page{
		background-color: #F3F3F3;
	}
	.btn {padding:20upx 0;}
	.btn button {margin:20upx 0;font-size:28upx;}
	.btn .logout {border-color:#175e3c;background: #EC2D16;color: #fff;}
</style>